<?php

include 'Base.php';

class Index extends Base
{



	public function test()
	{
        $param = $_REQUEST;

        if(empty(trim($param['date1']))){
            $this->returnFail('转换失败，请输入时间戳');
        }

        $time1 = date('Y-m-d H:i:s', $param['date1']);
		
		$this->returnSucess($time1);
	
	}


    //postman_json转apidoc
    public function postman_json2apidoc()
    {
        $param = $_REQUEST;
        $json_str = trim($param['input_data']);
        if(empty(trim($json_str))){
            $this->returnFail('转换失败');
        }

        $arr = json_decode($json_str,true);
        if(empty($arr) || !is_array($arr)){
            $this->returnFail('转换失败,结果为空');
        }

        $temp = [];
        foreach ($arr as &$info){
            $temp [$info['key']] = $info['value'];
        }

        $html_str = json_encode($temp, JSON_UNESCAPED_UNICODE);//[{"insert":"sdf"}]

        $this->returnSucess($html_str);

    }


    //postman_kv转apidoc
    public function postman_kv2apidoc()
    {
        $param = $_REQUEST;

        $input_data = trim($param['input_data']);

        if(empty(trim($input_data))){
            $this->returnFail('转换失败');
        }
        $arr = array_unique(explode(PHP_EOL, $input_data));
        if(empty($arr) || !is_array($arr)){
            $this->returnFail('转换失败,结果为空');
        }


        $temp = [];
        foreach ($arr as &$info){
            if(empty($info)){
                unset($info);
                continue;
            }
            $temp_arr = explode(':', $info);
            if(empty(trim($temp_arr[0]))){
                unset($info);
                continue;
            }
            $temp [trim($temp_arr[0])] =trim($temp_arr[1]);
        }

        $html_str = json_encode($temp, JSON_UNESCAPED_UNICODE);//[{"insert":"sdf"}]

        $this->returnSucess($html_str);

    }


}


$act = $_REQUEST['act'];
$obj = new Index();
$obj->$act();